gusucode.com > VC++ 界面很酷的一款多媒体播放器 > VC++ 界面很酷的一款多媒体播放器/gusucode/xMedia代码注释中/iniload.cpp
//Download by http://www.NewXing.com /**************************************** * File: iniload.cpp * * Last modified: 2004.2.7 * * Author: Yuanyi-Zhang * * Version: 0.0.0.1 * * CopyLeft 2004 xMedia team * ****************************************/ /**************************************************************** * * * This file may be distributed and/or modified under the terms * * of the GNU General Public License version 2 as published by * * the Free Software Foundation and appearing in the file * * LICENSE.GPL included in the packaging of this file. * * * ****************************************************************/ #pragma warning(disable:4786) #include <tchar.h> #include "iniload.h" #include <fstream> //读取配置文件 bool IniLoad::Load( string fname ) { if( fname.compare( _T( "" ) ) == 0 ) { return false; } ifstream in; string line; string key,value; size_t ip; in.open( fname.c_str() ); if( !in ) { return false; } while( in.good() ) { key = value = _T( "" ); getline( in, line ); ip = line.find_first_of( _T( "=" ) ); if ( ip==line.npos ) { continue; } key = line.substr( 0, ip ); value = line.substr( ip+1 ); ip = key.find_first_not_of( _T( " " ) ); if( ip == key.npos ) { continue; } key = key.substr( ip ); ip = key.find_first_of( _T( " " ) ); if( ip != key.npos ) { key = key.substr( 0, ip ); } ip = value.find_first_not_of( _T( " " ) ); if( ip == value.npos ) { continue; } value = value.substr( ip ); ip = value.find_first_of( _T( " " ) ); if( ip != value.npos ) { value = value.substr( 0, ip ); } m_IniMap[key] = value; } in.close(); return true; } ////////////////////////// //获取Key对应的Value string IniLoad::Get(string key) { map< string, string >::iterator im = m_IniMap.find( key ); if( im == m_IniMap.end() ) { return _T( "" ); } return m_IniMap[key]; } /////////////////////////// //设置Key对应的Value void IniLoad::Put(string key,string value) { m_IniMap[key] = value; }